package com.example.testproj.C0406;

import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.example.testproj.R;

public class GestureDetectorActivity extends AppCompatActivity {
    private GestureDetector.SimpleOnGestureListener listener;
    private Button button;
    private GestureDetector detector;
    private Handler handler=new Handler();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gesture_detector);

        button = (Button) findViewById(R.id.button3);

        listener = new GestureDetector.SimpleOnGestureListener() {
            @Override
            public boolean onDoubleTap(MotionEvent e) {
                Toast.makeText(GestureDetectorActivity.this, "双击6666", Toast.LENGTH_LONG).show();
                return super.onDoubleTap(e);
            }

            @Override
            public boolean onSingleTapConfirmed(MotionEvent e) {
                Toast.makeText(GestureDetectorActivity.this, "单击", Toast.LENGTH_LONG).show();
                return super.onSingleTapConfirmed(e);
            }
        };


        new Thread(){
            @Override
            public void run() {
                super.run();
                detector = new GestureDetector(GestureDetectorActivity.this, listener,handler);
            }
        }.start();


        button.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return detector.onTouchEvent(event);
            }
        });


    }
}
